package com.we.wecc.aw.api.controller;

import com.we.wecc.aw.db.model.FriendsBoost;
import com.we.wecc.aw.mid.model.out.FriendsBoostOut;
import com.we.wecc.aw.mid.service.FriendsBoostService;
import com.x.share.api.controller.BaseController;
import com.x.share.mid.exception.HelperException;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.Map;

@Api(value = "好友助力接口")
@RestController
@RequestMapping("/wecc/aw")
public class FriendsBoostController extends BaseController {

    @Resource
    FriendsBoostService friendsBoostService;

    @ApiOperation(value = "获取好友助力列表", notes= "获取好友助力列表", response = FriendsBoostOut.class)
    @RequestMapping(value = "/getFriendsList", method = { RequestMethod.GET})
    public @ResponseBody Map<String, Object> getFriendsList(
            @ApiParam(value = "用户id") @RequestParam("userId") Long userId,
            @ApiParam(value = "期数id") @RequestParam("awardId") int awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        FriendsBoostOut out = friendsBoostService.getFriendsList(userId, awardId);
        return success(out);
    }

    @ApiOperation(value = "好友助力", notes= "好友助力", response = FriendsBoost.class)
    @RequestMapping(value = "/boost", method = { RequestMethod.GET })
    public @ResponseBody Map<String, Object> boost(
            @ApiParam(value = "接受助力用户id") @RequestParam("awardUserId") Long awardUserId,
            @ApiParam(value = "期数id") @RequestParam("awardId") int awardId,
            @ApiParam(value = "用户id") @RequestParam("userId") Long userId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        FriendsBoost fb = friendsBoostService.boost(awardUserId, awardId, userId);
        return success(fb);
    }

    @ApiOperation(value = "本期助力的人数", notes= "本期用户当前助力的人数", response = Integer.class)
    @RequestMapping(value = "/getBoostNum", method = { RequestMethod.GET })
    public @ResponseBody Map<String, Object> getBoostNum(
            @ApiParam(value = "用户id") @RequestParam("userId") Long userId,
            @ApiParam(value = "期数id") @RequestParam("awardId") int awardId,
            @ApiParam(value = "应用id") @RequestHeader("appId") String appId,
            @ApiParam(value = "应用accessToken") @RequestHeader("atk") String atk) throws HelperException {
        Integer num = friendsBoostService.getBoostNum(userId, awardId);
        return success(num);
    }
}
